package com.helen.ui.helpordel;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.helen.adapter.SingleImgAdapter;
import com.helen.entity.HelpListEntity;
import com.helen.shopping.R;
import com.helen.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by yang on 2018/7/5.
 */

public class HelpOrderDetailActivity extends BaseActivity {
    @BindView(R.id.tv_help_order_status)
    TextView tvHelpOrderStatus;
    @BindView(R.id.img)
    ImageView img;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_detail_address)
    TextView tvDetailAddress;
    @BindView(R.id.img_address_right)
    ImageView imgAddressRight;
    @BindView(R.id.ll_address)
    LinearLayout llAddress;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_good_name)
    TextView tvGoodName;
    @BindView(R.id.tv_wx)
    TextView tvWx;
    @BindView(R.id.tv_dismissal)
    TextView tvDismissal;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    private HelpListEntity helpListEntity;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_help_order_detail;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText("详情");
        imgAddressRight.setVisibility(View.GONE);
        helpListEntity = (HelpListEntity) getIntent().getSerializableExtra("helpListEntity");
        setData(helpListEntity);
    }

    @Override
    protected void updateViews() {

    }


    private void setData(HelpListEntity helpListEntity) {
        int status = helpListEntity.getState();
        switch (status) {
            case 1:
                tvHelpOrderStatus.setText("等待状态: 待审核");
                break;
            case 2:
                tvHelpOrderStatus.setText("等待状态: 已审核");
                break;
            case 3:
                tvHelpOrderStatus.setText("审核失败");

                break;
        }

        tvNum.setText("数        量: " + helpListEntity.getCount());
        tvName.setText("收货人: " + helpListEntity.getName());
        tvPhone.setText(helpListEntity.getPhone());
        tvDetailAddress.setText("收货地址: " + helpListEntity.getCity());

        tvTitle.setText("求助标题: " + helpListEntity.getTitle());
        tvGoodName.setText("求助物品: " + helpListEntity.getType());
        if (!TextUtils.isEmpty(helpListEntity.getWx())) {
            tvWx.setText("微        信: " + helpListEntity.getWx());
        }
        tvContent.setText(helpListEntity.getContent());


        if(!TextUtils.isEmpty(helpListEntity.getDismissal())){
            tvDismissal.setText("驳回原因: "+helpListEntity.getDismissal());
            tvDismissal.setVisibility(View.VISIBLE);
        }else {
            tvDismissal.setVisibility(View.GONE);
        }


        List<String> commentImgList = new ArrayList<>();
        for (int i = 0;i<helpListEntity.getImg().size();i++){
            commentImgList.add(helpListEntity.getImg().get(i).getUrl());
        }
        SingleImgAdapter commentImgAdapter = new SingleImgAdapter(R.layout.item_comment_img_recycler, commentImgList);
        recycler.setLayoutManager(new GridLayoutManager(HelpOrderDetailActivity.this, 4));
        recycler.setAdapter(commentImgAdapter);
    }

}
